<template>
    <div class="topMain van-ellipsis">
      <div class="nav flex jcc aic pore" @click.self="closeModal">
        <div class="pore">
          <div class="searchInput flex" :class="isFocus ? 'onFocus' : ''">
            <div class="dis500">
              <van-field
                v-model="search"
                placeholder="请输入用户名"
                right-icon="aim"
                @focus="isFocus = true"
                @blur="isFocus = false"
                class="bdr"
              >
                <template #left-icon>
                  <div
                    class="flex aic selectLeft"
                    style="10px"
                    @click="openModal"
                  >
                    <div class="mgr10">{{ job }}</div>
                    <van-icon name="play" class="dowm" />
                  </div>
                </template>
                <template #extra>
                  <span class="mgl8 c9">地图</span>
                </template>
              </van-field>
            </div>
            <div class="ndis500">
              <van-field
                v-model="search"
                placeholder="请输入用户名"
                right-icon="aim"
                @focus="isFocus = true"
                @blur="isFocus = false"
                class="bdr"
              >
                <template #extra>
                  <span class="mgl8 c9">地图</span>
                </template>
              </van-field>
            </div>
            <van-button class="btn">搜索</van-button>
          </div>
          <div class="mgt10 mgl8">
            <div class="flex fww">
              <div class="mainTag" v-for="i in tagList">{{ i }}</div>
            </div>
          </div>
          <div class="mcard" v-if="showModel">
            <div
              v-for="(i, index) in joinType"
              class="lineSpan"
              @mouseenter="leftMouse(index)"
            >
              <div>{{ i.name }}</div>
              <van-icon name="play" />
            </div>
          </div>
          <div class="sonCard" v-if="leftActive >= 0">
            <div class="pd8">
              <div class="fs14 mgb10">{{ joinType[leftActive].name }}</div>
              <div class="fs12" v-for="j in joinType[leftActive].children">
                <div class="flex jcsb">
                  <div class="sonName">{{ j.name }}</div>
                  <div class="flex fww f1">
                    <div class="minType" v-for="k in j.list">
                      <div>{{ k }}</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </template>
  <style scoped>
  @import "../../public.css";
  @import "../../ui/vant-ui/ui.css";
  .topMain {
    font-size: 12px;
    color: #666;
  }
  .searchInput .btn {
    border: none;
    width: 100px;
    background-color: var(--primary-color);
    color: #fff;
    transform: translate(-2px, 0);
  }
  .selectLeft:hover {
    color: var(--primary-color);
  }
  .dowm {
    transform: rotate(90deg);
    font-size: 12px;
  }
  .bdr {
    border-radius: 5px;
    z-index: 100;
    width: 450px;
  }
  .nav {
    width: 100%;
    height: 400px;
    background-color: var(--primary-color);
    background-image: url("../../img/mainNav.jpg");
    background-repeat: no-repeat;
    background-size: 100% 100%;
  }
  .searchInput {
    width: 550px;
    opacity: 0.4;
    border: 2px solid var(--primary-color);
    background-color: var(--primary-color);
    border-radius: 8px;
  }
  .searchInput:hover,
  .onFocus {
    opacity: 1;
  }
  .mcard {
    position: absolute;
    padding: 10px;
    left: 0px;
    top: 50px;
    width: 100px;
    height: 130px;
    background-color: #fff;
    border-radius: 5px;
    color: #000;
    overflow-y: scroll;
  }
  .sonCard {
    position: absolute;
    left: 130px;
    top: 50px;
    width: 400px;
    height: 150px;
    background-color: #fff;
    border-radius: 5px;
    color: #000;
    overflow-y: scroll;
  }
  .lineSpan {
    display: flex;
    justify-content: space-between;
    padding: 8px;
  }
  .lineSpan:hover {
    color: var(--primary-color);
  }
  .sonName {
    width: 70px;
    margin: 8px;
  }
  .minType {
    margin: 8px;
  }
  .minType:hover {
    color: var(--primary-color);
  }
  .mainTag{
      display: inline;
      padding: 5px;
      border-radius: 5px;
      margin-right: 5px;
      background-color: #eeeeee65;
      color: var(--primary-color);
      letter-spacing:0;
      font-size: 12px;
    }
    .mainTag:hover{
      background-color: var(--primary-color);
      color: #fff;
    }
  @media (max-width: 500px) {
    .searchInput {
      width: 300px !important;
    }
    .sonCard {
      width: 180px !important;
    }
    .bdr {
      width: 220px !important;
    }
  }
  </style>
  <script>
  module.exports = {
    data() {
      return {
        tagList:['tag1','tag2','tag3','tag4','tag5',],
        active: 0,
        search: "",
        isFocus: false,
        job: "xxxx",
        jobleft: ["大类1", "大类2", "大类3", "大类4", "大类5", "大类6"],
        joinType: [
          {
            name: "大类1",
            children: [
              {
                name: "标题1",
                list: [
                  "子类1",
                  "子类2",
                  "子类3",
                  "子类4",
                  "子类5",
                  "子类1",
                  "子类2",
                  "子类3",
                  "子类4",
                  "子类5",
                  "子类1",
                  "子类2",
                  "子类3",
                  "子类4",
                  "子类5",
                ],
              },
            ],
          },
          {
            name: "大类2",
            children: [
              {
                name: "标题2",
                list: ["子类1", "子类2", "子类3", "子类4", "子类5"],
              },
            ],
          },
          {
            name: "大类3",
            children: [
              {
                name: "标题3",
                list: ["子类1", "子类2", "子类3", "子类4", "子类5"],
              },
            ],
          },
          {
            name: "大类4",
            children: [
              {
                name: "标题4",
                list: ["子类1", "子类2", "子类3", "子类4", "子类5"],
              },
            ],
          },
        ],
        showModel: false,
        leftActive: -1,
      };
    },
    props: {},
    methods: {
      openModal() {
        this.showModel = true;
        // 在打开弹窗时，添加全局点击事件监听
        document.addEventListener("click", this.closeModalOnOutsideClick);
      },
      closeModal() {
        this.showModel = false;
        this.leftActive = -1;
        // 在关闭弹窗时，移除全局点击事件监听
        document.removeEventListener("click", this.closeModalOnOutsideClick);
      },
      closeModalOnOutsideClick(event) {
        // 获取弹窗元素的引用
        const modal = this.$refs.modal;
        // 如果点击的区域不在弹窗内部，则关闭弹窗
        if (modal && !modal.contains(event.target)) {
          this.closeModal();
        }
      },
      leftMouse(index) {
        this.leftActive = index;
      },
      topage(url){
        window.location.href = url;
      }
    },
  };
  </script>
  